package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;

import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.thread.UserThreadLocal;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.service.IMemberReservationService;
import com.zzyl.nursing.vo.RecordVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约信息Controller
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags = "预约信息相关接口")
public class MemberReservationController extends BaseController {

    @Autowired
    private IMemberReservationService imemberReservationService;

    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public R<Integer> getCancelledReservationCount() {
        Long userId = UserThreadLocal.getUserId();
        Integer count = imemberReservationService.getCancelledReservationCount(userId);
        return R.ok(count);
    }

    @GetMapping("/countByTime")
    @ApiOperation("查询每个阶段剩余预约数量")
    public R<RecordVo> getReservationCountByTime(@RequestParam Long time) {
        RecordVo reservationCountByTime = imemberReservationService.getReservationCountByTime(time);
        return R.ok(reservationCountByTime);
    }


    @PostMapping
    @ApiOperation("新增预约信息")
    public AjaxResult add(@RequestBody Reservation reservation){
        imemberReservationService.add(reservation);
        return success();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询预约信息")
    public R<TableDataInfo<List<Reservation>>> page(Reservation reservation) {
        startPage();
        List<Reservation> list = imemberReservationService.selectReservationList(reservation);
        return R.ok(getDataTable(list));
    }


    @PutMapping("/{id}/cancel")
    @ApiOperation("修改预约信息")
    public AjaxResult cancel(@PathVariable Long id){
        imemberReservationService.cancel(id);
        return success();
    }
}